<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <span>{{sex | formatterDate('-')}}</span>
    </div>
    <script src="../vue.js"></script>
    <script>
        new Vue({
            el:'#app',
            data () {
                return {
                    sex:'2021/5/23',
                }
            },
            filters: {
                formatterDate(val,str){
                    // //：正则 //g:g:全局  //i:不区分大小写
                    let str1=val.replace(/\//g,str);
                    let arr=str1.split('-');
                    let str3=arr[1].padStart(2,'0'); //在开头：padStart(长度，'补的值')   在结尾padEnd
                    return `${arr[0]}-${str3}-${arr[2]}`;
                }
            }
        })
    </script>
</body>
</html>